<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function loadName(){
		var xmlHttp;
		/* 如果有XMLHttpRequest对象，直接创建 */
		if(window.XMLHttpRequest){
			xmlHttp=new XMLHttpRequest();
		}else{
			/* 如果没有，则利用ActiveXObject对象 */
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		alert("readystate状态:"+xmlHttp.readyState+",status状态:"+xmlHttp.status);
		xmlHttp.onreadystatechange=function(){
			alert("readystate状态:"+xmlHttp.readyState+",status状态:"+xmlHttp.status);
			if(xmlHttp.readyState==4 && xmlHttp.status==200){
				alert(xmlHttp.responseText);
				document.getElementById("name").value=xmlHttp.responseText;
			}
		}
		
		/* 调用open方法，利用get异步请求 */
		xmlHttp.open("get","getAjaxName",true);
		/* 调用send方法发送请求 */
		xmlHttp.send();
	}
</script>
</head>
<body>
<div style="text-align: center;">
	<div>
		<input type="button" value="Ajax获取数据" onclick="loadName()"/>&nbsp;&nbsp;<input type="text" id="name" name="name"/>
	</div>
</div>
</body>
</html>